/**
 * @Author: 陈瑞鹏
 * @Date:   2022-12-05 17:39:01
 * @Last Modified by:   陈瑞鹏
 * @Last Modified time: 2022-12-05 17:42:28
 */
import { Mediator } from "../pureMvc/patterns/mediator/Mediator";

import { INotification } from "../pureMvc/Interfaces";
import BaseGameComponent from "./BaseGameComponent";
import { GameFacade } from "./GameFacade";

export class MediatorComponent extends Mediator {
    private static MEDIATOR_COMPONET_INDEX: number = 0;
    private displayObject: BaseGameComponent = null;
    public constructor(mediatorName: string, displayObject: BaseGameComponent) {
        super(mediatorName + MediatorComponent.MEDIATOR_COMPONET_INDEX++);
        this.bindingDisplayObject(displayObject);
        // this.registerMediator();
    }

    public registerMediator(): void {
        GameFacade.getInstance().registerMediator(this);
    }

    public removeMediator(): void {
        GameFacade.getInstance().removeMediator(this.getMediatorName());
    }

    private bindingDisplayObject(displayObject: BaseGameComponent): void {
        this.displayObject = displayObject;
    }

    /**
 * 绑定的事件 数组
 */
    public listNotificationInterests(): string[] {

        return this.displayObject.listNotificationInterests();
    }

    /**
     * 事件 响应方法
     * @param notification 
     */
    public handleNotification(notification: INotification): void {
        this.displayObject.handleNotification(notification);
    }
}